# Build Information (automatically generated)
NODE_VER_MAJ=	@NODE_VER_MAJ@
NODE_VER_MIN=	@NODE_VER_MIN@
NODE_BUILD=	@NODE_BUILD@
NODE_VER_FULL=	@PACKAGE_VERSION@

STORE_TYPE=	@STORE_TYPE@
VERBOSE=	@VERBOSE@

CC=		"/usr/bin/gcc-3.4"
CPPFLAGS=	-Iinclude -Isrc/zlib -Isrc/expat @CPPFLAGS@
CFLAGS=		$(CPPFLAGS) @CFLAGS@
LDFLAGS=	@LDFLAGS@
LIBS=		@LIBS@

# Setting verbosity
ifeq ($(VERBOSE),no)
CC:=		@${CC}
DEP_MSG=	@echo "==> Creating dependencies..."
CC_MSG=		@echo "==> Compiling $<..."
LD_MSG=		@echo "==> Linking $@..."
endif

OBJ=obj

PROG1=entropy_rsa
OBJS1=\
	${OBJ}/entropy.o \
	${OBJ}/logger.o \
	${OBJ}/funclib.o \
	${OBJ}/osd.o \
	${OBJ}/tools.o \
	${OBJ}/i18n.o \
	${OBJ}/mime.o \
	${OBJ}/temp.o \
	${OBJ}/memalloc.o \
	${OBJ}/shmalloc.o \
	${OBJ}/config.o \
	${OBJ}/base64.o \
	${OBJ}/sha1.o \
	${OBJ}/ek5.o \
	${OBJ}/key.o \
	${OBJ}/uri.o \
	${OBJ}/bignum.o \
	${OBJ}/twofish2.o \
	${OBJ}/crypt.o \
	${OBJ}/crypt0.o \
	${OBJ}/crypt7.o \
	${OBJ}/fec.o \
	${OBJ}/file.o \
	${OBJ}/sock.o \
	${OBJ}/store.o \
	${OBJ}/client.o \
	${OBJ}/peermsg.o \
	${OBJ}/peer.o \
	${OBJ}/ipv4_list.o \
	${OBJ}/gif.o \
	${OBJ}/png.o \
	${OBJ}/unicode.o \
	${OBJ}/vt.o \
	${OBJ}/zlib/adler32.o \
	${OBJ}/zlib/compress.o \
	${OBJ}/zlib/crc32.o \
	${OBJ}/zlib/deflate.o \
	${OBJ}/zlib/gzio.o \
	${OBJ}/zlib/infback.o \
	${OBJ}/zlib/inffast.o \
	${OBJ}/zlib/inflate.o \
	${OBJ}/zlib/inftrees.o \
	${OBJ}/zlib/trees.o \
	${OBJ}/zlib/uncompr.o \
	${OBJ}/zlib/zutil.o \
	${OBJ}/expat/xmlparse.o \
	${OBJ}/expat/xmlrole.o \
	${OBJ}/expat/xmltok.o \
	${OBJ}/proxy.o \
	${OBJ}/news.o

ifeq ($(STORE_TYPE),1)
OBJS1+=${OBJ}/store_tree.o
else
ifeq ($(STORE_TYPE),2)
OBJS1+=${OBJ}/store_mysql.o
else
OBJS1+=${OBJ}/store_mono.o
endif
endif

PROG2=storechg
OBJS2=${OBJ}/storechg.o \
	${OBJ}/funclib.o

PROG3=monoopt
OBJS3=${OBJ}/monoopt.o

BINDIR=$(PROG1)-$(NODE_VER_MAJ).$(NODE_VER_MIN)
DIST=$(PROG1)-$(NODE_VER_FULL)
WINDIST=/home/$(BINDIR)
INSTALLCMD=install.cmd
UPDATECMD=update.cmd
RUNBAT=$(WINDIST)/run.bat
STOPBAT=$(WINDIST)/stop.bat
ISS_FILE=entropy.iss
DISTDIR=/cygdrive/c/dist/
CYGLIBS=/bin/cygz.dll /bin/cygexpat-0.dll /bin/cygiconv-2.dll /bin/cygintl-2.dll /bin/cygpopt-0.dll /bin/cygwin1.dll
COPYEXE=/bin/sh.exe /bin/cp.exe /bin/ps.exe /bin/kill.exe /bin/mkshortcut.exe /bin/cygstart.exe




all:	$(OBJ) .depend $(PROG1) $(PROG2) $(PROG3)
	@echo "==> @target@ build done"

$(DEPS):	$(OBJ) Makefile

dist:	mostlyclean
	mkdir -p ../tmp/$(BINDIR)
	rm -rf ../tmp/$(BINDIR)/*
	cp -p Makefile.in config.guess config.sub configure configure.ac install-sh LICENSE README README.MySQL TODO CODINGRULES ENTROPY.html *-dist run.sh stop.sh ../tmp/$(BINDIR)
	find node -type f -mindepth 1 | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	find chat -type f -mindepth 1 | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	find ?? -name "*.lo" | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	find src -name "*.c" | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	find src -name "*.h" | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	find include -name "*.h*" | grep -v CVS | cpio -padm ../tmp/$(BINDIR)
	tar -C ../tmp -c -z -f ../entropy_html/files/$(DIST).tgz $(BINDIR)

windist:	todos
	/bin/rm -rf $(WINDIST)
	/bin/mkdir $(WINDIST)
	/bin/mkdir $(WINDIST)/de
	/bin/mkdir $(WINDIST)/node
	/bin/mkdir $(WINDIST)/chat
	/bin/cp LICENSE README TODO ENTROPY.html $(WINDIST)
	./todos entropy_rsa.conf-dist $(WINDIST)/entropy_rsa.conf
	./todos entropy_rsa.conf-dist $(WINDIST)/entropy_rsa.conf-dist
	./todos seed.txt-dist $(WINDIST)/seed.txt-dist
	/bin/cp entropy_rsa.exe storechg.exe monoopt.exe entropy.ico handstop.ico $(WINDIST)
	/bin/cp de/entropy_rsa.lo $(WINDIST)/de
	/bin/cp node/*.css node/*.gz node/*.html node/*.gif node/*.png node/*.txt node/*.types $(WINDIST)/node
	/bin/cp chat/*.html $(WINDIST)/chat
	./todos $(INSTALLCMD).template $(WINDIST)/$(INSTALLCMD)
	./todos $(UPDATECMD).template $(WINDIST)/$(UPDATECMD)
	@echo -e "@ECHO OFF\r" >$(RUNBAT)
	@echo -e "ECHO Starte ENTROPY\r" >>$(RUNBAT)
	@echo -e "set CYGWIN=\r" >>$(RUNBAT)
	@echo -e "entropy_rsa.exe --verbose --autorun\r" >>$(RUNBAT)
	@echo -e "@ECHO OFF\r" >$(STOPBAT)
	@echo -e "ECHO Beende ENTROPY\r" >>$(STOPBAT)
	@echo -e "entropy_rsa.exe --verbose --kill\r" >>$(STOPBAT)
	PWD=`pwd`
	cd $(WINDIST)/..;/bin/zip -r $(DISTDIR)$(DIST)-win32.zip $(BINDIR);cd $(PWD)

wininstaller:   windist
	/bin/rm -rf $(DISTDIR)$(BINDIR)
	/bin/cp -Rv $(WINDIST) $(DISTDIR)$(BINDIR)
	./todos $(ISS_FILE).template $(ISS_FILE)
	iscc $(ISS_FILE)

cygtool:
	/bin/zip -rj $(DISTDIR)cygtools.zip $(CYGLIBS) $(COPYEXE)


$(OBJ):
	@mkdir $(OBJ) > /dev/null 2>&1
	@mkdir $(OBJ)/zlib > /dev/null 2>&1
	@mkdir $(OBJ)/expat > /dev/null 2>&1

.depend: $(wildcard src/*.c) $(wildcard include/*.h)
	$(DEP_MSG)
	$(CC) $(CPPFLAGS) -E -MM src/*.c >$@

$(OBJ)/%.o:	src/%.c
	$(CC_MSG)
	$(CC) $(CFLAGS) -o $@ -c $<

$(PROG1):	$(OBJS1)
	$(LD_MSG)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

$(PROG2):	$(OBJS2)
	$(LD_MSG)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

$(PROG3):	$(OBJS3)
	$(LD_MSG)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

fec:	obj/logger.o src/fec.c
	$(CC) $(CFLAGS) -DTESTFEC -o $@ $^

ek5:	obj/logger.o src/ek5.c
	$(CC) $(CFLAGS) -DEK5_TEST -o $@ $^

crypt7:	obj/logger.o obj/twofish2.o src/crypt7.c
	$(CC) $(CFLAGS) -DCRYPT7_TEST -o $@ $^

fishtest:	src/twofish2.c
	$(CC) $(CFLAGS) -DTEST_2FISH -o $@ $^

crypt: obj/logger.o obj/memalloc.o obj/base64.o obj/key.o obj/sha1.o obj/ek5.o obj/tools.o obj/i18n.o obj/unicode.o obj/zlib/adler32.o obj/zlib/compress.o obj/zlib/crc32.o obj/zlib/deflate.o obj/zlib/gzio.o obj/zlib/infback.o obj/zlib/inffast.o obj/zlib/inflate.o obj/zlib/inftrees.o obj/zlib/trees.o obj/zlib/uncompr.o obj/zlib/zutil.o obj/twofish2.o obj/crypt0.o obj/crypt7.o src/crypt.c
	$(CC) $(CFLAGS) -DCRYPT_TEST -o $@ $^

cryptp: obj/logger.o obj/memalloc.o obj/base64.o obj/key.o obj/sha1.o obj/ek5.o obj/tools.o obj/i18n.o obj/unicode.o obj/zlib/adler32.o obj/zlib/compress.o obj/zlib/crc32.o obj/zlib/deflate.o obj/zlib/gzio.o obj/zlib/infback.o obj/zlib/inffast.o obj/zlib/inflate.o obj/zlib/inftrees.o obj/zlib/trees.o obj/zlib/uncompr.o obj/zlib/zutil.o obj/twofish2.o obj/crypt0.o obj/crypt7.o src/crypt.c
	$(CC) $(CFLAGS) -DCRYPT_TEST -DCRYPT_TEST_PRINT -o $@ $^

bignum:	src/bignum.c
	$(CC) $(CFLAGS) -DBN_TEST=1 -o $@ $^

todos:	Makefile src2/todos.c
	$(CC) $(CFLAGS) -o $@ src2/todos.c

clean:
	-rm -rf $(OBJ) $(PROG1) $(PROG2) $(PROG3) $(PROG4) $(PROG5) *.core *.log todos.exe .depend entropy.pid fec fishtest

mostlyclean: clean
	-rm -rf config.cache config.log config.status configure.lineno
	-rm -rf autom4te.cache include/config.h include/config.h.in~

distclean: mostlyclean
	-rm -rf Makefile

ifneq ($(wildcard .depend),)
include .depend
endif
